<?php

require_once 'Zend/Controller/Front.php';
require_once 'Zend/View/Helper/Url.php';

class Sfs_View_Helper_Route extends Zend_View_Helper_Url
{
	public function route($action = null, $controller = null,
	$module = null, $params = array(), $route = null)
	{
		$front = Zend_Controller_Front::getInstance();
		$request = $front->getRequest();
		$router = $front->getRouter();

		if ($action === null) {
			$action = $request->getActionName();
		}
		if ($controller === null) {
			$controller = $request->getControllerName();
		}
		if ($module === null) {
			$module = $request->getModuleName();
		}

		$urlOptions = array_merge($params, array(
            'action' => $action,
            'controller' => $controller,
            'module' => $module
		));

		if ($router->hasRoute($controller) && $route === null) {
			$route = $controller;
		} else if ($route === null) {
			$route = 'default';
		}

		return $this->url($urlOptions, $route, true);
	}
}